/*
 * Copyright 2009 Andreas Borglin andreas.borglin@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package borge.mobile.app.jakoon;

import borge.mobile.app.jakoon.Main.ESwtExecutor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Slider;

/**
 * Form for loading certain image settings at bottom of image screen
 * @author Andreas Borglin
 */
public class ImageBottomForm {

    private Label label;
    private Slider slider;
    private Button button;
    
    private Composite parent;
    private Composite comp;
    private ESwtExecutor executor;
    private ImageForm imageForm;

    private static final String VALUE = "Value: ";
    private static final int DEFAULT = 0;
    public static final int DEFAULT_INTERNAL = 50;
    
    public ImageBottomForm(ESwtExecutor exec, Composite parent, ImageForm imgForm) {
            
        this.parent = parent;
        executor = exec;
        imageForm = imgForm;
        
        comp = new Composite(parent, SWT.NONE);
        RowLayout layout = new RowLayout();
        layout.type = SWT.HORIZONTAL;
        layout.wrap = false;
        comp.setLayout(layout);
        
        slider = new Slider(comp, SWT.HORIZONTAL);
        slider.setMinimum(0);
        slider.setMaximum(100);
        slider.setSelection(DEFAULT_INTERNAL);
        slider.addSelectionListener(new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent event) {}
            public void widgetSelected(SelectionEvent event) {
                Slider s = (Slider) event.getSource();
                label.setText(VALUE + (s.getSelection()-50));
                label.pack();
            }
        });
        
        label = new Label(comp, SWT.NONE);
        label.setText(VALUE + DEFAULT);
        
        button = new Button(comp, SWT.PUSH);
        button.setText("Apply");
        button.addSelectionListener(new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent event) {}
            public void widgetSelected(SelectionEvent event) {
                imageForm.bottomFormCallback(slider.getSelection());
            }
        });
        
        
        comp.layout();
    }
    
    protected void setVisible(boolean visible){
        comp.setVisible(visible);
        comp.layout();
    }
    
    protected void reset(){
        slider.setSelection(DEFAULT_INTERNAL);
        label.setText(VALUE + DEFAULT);
        label.pack();
    }
    

}
